/*
 * Pass2.h
 *
 *  Created on: May 13, 2012
 *      Author: miro
 */

#ifndef PASS2_H_
#define PASS2_H_

#include <iostream>
#include <fstream>
#include <string>
#include <ctype.h>
#include <utility>
#include <stdio.h>
#include <math.h>
#include <map>
#include <stack>;
#include <iomanip>
#include <locale>
#include <fstream>
#include "LabelObject.h"
#include "Flag.h"
#include "Line.h"
#include "symbolChecker.h"
using namespace counter;
using namespace std;
using namespace __gnu_cxx;

class Pass2 {
public:
        //format 4
        int MAX_HEX_20;
        int MAX_DEC_20;
        // base
        int MAX_HEX_12;
        int MAX_DEC_12;
        //pc counter
        //max
        int MAX_HEX_11;
        int MAX_DEC_11;
        Flag flag;
        symbolChecker *checker;
        map<string, LabelObject> symbolTable;
        map<string, int> litPool;
        vector<Line*> input;
        bool base;
        int baseValue;
        Pass2();
        Pass2(map<string, LabelObject> symbolTable, map<string, int> litPool,
                        vector<Line*> input);
        virtual ~Pass2();
        string getOperand(Line* line);
        void setFlags(int no);
        int calcDisp(int lineNo);
        void setObjectProgram();
        string convertToObjectCode(vector<int> input, int format);

        int binaryToBase10(int n);

        void writeFile(char* fileName);
  string int2hex(unsigned int dec);
  string int2string( int number);
  string generateStart(string name,int start,int end) ;
  string modificationRecored(int start,int currentAddress);
  void objectPrograme(vector<Line> input);

private:

        vector<int> calcFormat2(Line *curr);
        bool checkIndexed(int lineNo);
        int calcForBaseAndPC(int lineNo, string operand, int pc);
        int calcFormat4(int lineNo, string operand);
        int calcFormat3(int lineNo, string operand, int pc);
        int calculateDiff(int n);
        int checkBaseOrPC(int n);

        int calcFormat1(int lineNo);

};

#endif /* PASS2_H_ */
